﻿function Request()
{
    var object=this;
    
    this.Url;
    this.Method="Get";
    this.Callback;
    this.Data;
    this.Enctype="application/x-www-form-urlencoded";
    
    if(!window.XMLHttpRequest) window.XMLHttpRequest=function()
	{
		var progIDs=["Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
		for(var i=0;i<progIDs.length;i++)
		{
			try
			{
				var xmlHttp=new ActiveXObject(progIDs[i]);
				return xmlHttp;
			}
			catch(ex)
			{			
			}
		}
		return null;
	};
    
    this.Start=function Start()
    {    
        var httpRequest=new XMLHttpRequest();  	     	
		httpRequest.onreadystatechange = function()
		{			   
			if (httpRequest.readyState==4)
			{          
				object.Callback(httpRequest);
			}
		}
		httpRequest.open(this.Method,this.Url,true);		
		if (this.Method=="Post") httpRequest.setRequestHeader("Content-Type", this.Enctype);
		httpRequest.send(this.Data);
    }
}

function GetLeft(src){
	var left=0;
	while(src){
		left+=src.offsetLeft;
		src=src.offsetParent;
	}
	return left;
}
function GetTop(src){
	var top=0;
	while(src){
		top+=src.offsetTop;
		src=src.offsetParent;
	}
	return top;
}
function Cookie()
{	
	this.SetCookie = function(sName, sValue, nExpireDays, sDomain, sPath)
	{
		var sCookie = sName+"="+escape(sValue)+";";
		if (nExpireDays)
		{
			var oDate = new Date();
			oDate.setMilliseconds(oDate.getMilliseconds()+parseInt(nExpireDays)*24*3600*1000);
			sCookie += "expires="+oDate.toUTCString()+";";
		}
		if (sDomain)
		{
			sCookie += "domain="+sDomain+";";
		}
		if (sPath)
		{
			sCookie += "path="+sPath+";"
		}
		
		document.cookie = sCookie;
	}
	
	this.GetCookie = function(sName)
	{
		var aCookie = document.cookie.split("; ");
		for (var i=0; i < aCookie.length; i++)
		{
			var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0])
			{
				return aCrumb.length>=2 ? unescape(aCrumb[1]) : "";
			}
		}
		return null;
	}
}
function Dialog(title,x,y,width,height)
{
	var object=this;
	var dialogMask;

    this.Title=title?title:"无标题";
    this.Width=width?width:300;
    this.Height=height?height:200;
    this.X=x?x:(document.documentElement.clientWidth-this.Width)/2;
    this.Y=y?y:document.documentElement.scrollTop+(document.documentElement.clientHeight-this.Height)/2;

    this.SetTitle=function (title)
    {
        this.Title=title;
        headerCenter.innerHTML=this.Title;  
    }   
    this.SetXY=function (x,y)
    {
       this.X=x;
       this.Y=y;
       this.Dialog.style.left=this.X+"px";
       this.Dialog.style.top=this.Y+"px";
    }    
    
   
    this.SetRange=function (width,height)
    {
        this.Width=width;
        this.Height=height;
        this.X=x?x:(document.documentElement.clientWidth-this.Width)/2;
        this.Y=y?y:document.documentElement.scrollTop+(document.documentElement.clientHeight-this.Height)/2;
        this.Dialog.style.left=this.X+"px";
        this.Dialog.style.top=this.Y+"px";
        this.Dialog.style.width=this.Width+"px";
        this.Dialog.style.top=this.Height+"px";
    }
    
    this.Show=function ()
    {
       this.Dialog.style.display="block";
    }    
    this.Hide=function ()
    {
       if (dialogMask)
       {
          dialogMask.style.display="none";
       }
       this.Dialog.style.display="none";
    }
    
    this.Close=function ()
    {
       if (dialogMask)
       {
           dialogMask.parentNode.removeChild(dialogMask);
       }
       this.Dialog.parentNode.removeChild(this.Dialog);
       this.Dispose();
    }
    
    this.Dispose=function ()
    {       
       this.Dialog=null;
       delete dialogMask;
       dialogMask=null;
       delete object;
       object=null;
    }
    
    if (window.attachEvent) {
		window.attachEvent("onunload", this.Dispose);
	}
	else {
		window.addEventListener("unload", this.Dispose, false);
	};
    
    this.Alert=function (message)
    {
        this.showModelessDialog();
        this.Dialog.childNodes[1].innerHTML="<div class='DialogContentLeft'></div><div class='DialogContentRight'>"+message+"</div><div class='DialogContentButton'><INPUT class='Button' type='button' value='  确 定  ' onmouseover=\"javascript:this.className='ButtonOver'\" onmouseout=\"javascript:this.className='Button'\" onclick='javascript:this.parentNode.parentNode.parentNode.Dialog.Close();this.parentNode.parentNode.parentNode.Dialog.Alert.Dispose();'></div>";
        this.Dialog.lastChild.style.height=this.Dialog.offsetHeight+"px";
    }
    this.Confirm=function (message)
    {
        this.showModelessDialog();
        this.Dialog.childNodes[1].innerHTML="<div class='DialogContentLeft'></div><div class='DialogContentRight'>"+message+"</div><div class='DialogContentButton'><INPUT class='Button' type='button' value=' 确 定 ' onmouseover=\"javascript:this.className='ButtonOver'\" onmouseout=\"javascript:this.className='Button'\" onclick='javascript:this.parentNode.parentNode.parentNode.Dialog.Close();this.parentNode.parentNode.parentNode.Dialog.Confirm.OK();'>&nbsp;&nbsp;&nbsp;<INPUT class='Button' type='button' value=' 取 消 ' onmouseover=\"javascript:this.className='ButtonOver'\" onmouseout=\"javascript:this.className='Button'\" onclick='javascript:this.parentNode.parentNode.parentNode.Dialog.Close();this.parentNode.parentNode.parentNode.Dialog.Confirm.Cancel();'></div>";
        this.Dialog.lastChild.style.height=this.Dialog.offsetHeight+"px";
    }
    this.showModelessDialog=function ()
    {
        dialogMask=document.createElement("div");
        dialogMask.className="DialogMask";
        document.body.appendChild(dialogMask);	
        dialogMask.style.height=document.body.clientHeight+"px";
    }

 	var dialog=this.Dialog=document.createElement("div");
    document.body.appendChild(dialog);	

	dialog.className="Dialog";
	dialog.Dialog=this;   
    
           
    dialog.style.left=this.X+"px";
	dialog.style.top=this.Y+"px";
	dialog.style.width=this.Width+"px";	
	


	
	var header=document.createElement("div");
	header.className="DialogHeader";
	dialog.appendChild(header);
	
	var headerLeft=document.createElement("div");
	headerLeft.className="DialogHeaderLeft";
	header.appendChild(headerLeft);
	
    var expandImage=document.createElement("div");
	expandImage.className="DialogExpandImage";
	expandImage.setAttribute("State","Expand");
	expandImage.onmouseover=function () {this.className="Dialog"+this.getAttribute("State")+"ImageOver";};
	expandImage.onmouseout=function () {this.className="Dialog"+this.getAttribute("State")+"Image";};
	expandImage.onmousedown=function (e) 
	{
		if (e)
		{
			window.event=e;
		}
   		window.event.cancelBubble = true; 
   		var content=this.parentNode.parentNode.parentNode.childNodes[1];
   		var footer=this.parentNode.parentNode.parentNode.childNodes[2];
		if (this.getAttribute("State")=="Expand")
		{    	   	   
       	   	this.title="展开";
      		this.setAttribute("State","Collapse");
			content.style.display="none";
			footer.style.display="none";
		}
		else
		{
			this.title="折叠";
      		this.setAttribute("State","Expand");
			content.style.display="block";
			footer.style.display="block";
		}
		content=null;
		footer=null;
		this.className="Dialog"+this.getAttribute("State")+"ImageOver";
	} 
	headerLeft.appendChild(expandImage);
	
	
	var headerCenter=document.createElement("div");
	headerCenter.className="DialogHeaderCenter";
	headerCenter.innerHTML=this.Title;		
	header.appendChild(headerCenter);		
			
	var headerRight=document.createElement("div");
	headerRight.className="DialogHeaderRight";
	header.appendChild(headerRight);
	
	var closeImage=document.createElement("div");
	closeImage.className="DialogCloseImage";
	closeImage.title="关闭";
	closeImage.onmouseover=function () {this.className="DialogCloseImageOver";};
	closeImage.onmouseout=function () {this.className="DialogCloseImage";};
	closeImage.onmousedown=function (e) 
	{		 
	    window.event.returnValue = true;    
  		object.Close();
	}
	headerRight.appendChild(closeImage);	

		
	var content=document.createElement("div");
	content.className="DialogContent";
	dialog.appendChild(content);  
			
	var footer=document.createElement("div");
	footer.className="DialogFooter";
	dialog.appendChild(footer);  	

    var iframe=document.createElement("iframe");
	iframe.className="MaskDiv";
	dialog.appendChild(iframe);
	
	header.onmousedown=function (e)
	{		
		if (e)
		{
			window.event=e;
			window.event.srcElement=e.target;      
		}
		window.event.returnValue = true;
		var dialog=this.parentNode;   
		var header=this;
		this.style.cursor="move";
		var offsetX=window.event.clientX-GetLeft(dialog);
		var offsetY=window.event.clientY-GetTop(dialog);
		document.onmousemove=function (e)
		{
			if (e)
			{
				window.event=e;
				window.event.srcElement=e.target;      
			}
    		window.event.returnValue = true;   
    		object.SetXY(window.event.clientX-offsetX,window.event.clientY-offsetY);
         }
         document.onmouseup=function (e)
		 {
		    header.style.cursor="";
			document.onmousemove=null;
			document.onmouseup=null;
			dialog=null;
			header=null;
		 }
    }  
    delete expandImage;
	expandImage=null;
	delete closeImage;
	closeImage=null;
				
	delete headerLeft;
	headerLeft=null;
	delete headerCenter;
	headerCenter=null;				
	delete headerRight;
	headerRight=null;
	
	delete header;
	header=null;
	delete footer;
	footer=null;
	delete content;
	content=null;
	delete dialog;
	dialog=null; 
};
function User()
{
    var object=this;
    this.Value=new Array();
    
	var dialog=new Dialog("选择用户");
	var dialogContent=dialog.Dialog.childNodes[1];
	dialog.Dialog.style.top=document.documentElement.scrollTop+50+"px";
	
	var organize=document.createElement("div");	
	organize.className="Section";
	dialogContent.appendChild(organize); 
	
	var toolbar=document.createElement("div");
	toolbar.className="DialogToolBar";
	dialogContent.appendChild(toolbar);
	
	var toolbarLeft=document.createElement("div");
	toolbarLeft.className="DialogToolItemLeft";
	toolbar.appendChild(toolbarLeft);
	
	var okButton=document.createElement("input");
	okButton.setAttribute("type","button");
	toolbarLeft.appendChild(okButton);  	
	okButton.className="Button";
	okButton.value=" 确  定 ";
	okButton.onmouseover=function ()
	{
	    this.className="ButtonOver";
	};
	okButton.onmouseout=function ()
	{
	    this.className="Button";
	};
	okButton.onclick=function ()
	{
	   var organize=this.parentNode.parentNode.parentNode.childNodes[0];
	   var checkboxes=organize.getElementsByTagName("input");
	   for (var i=0;i<checkboxes.length;i++)
	   {
	        if (checkboxes[i].checked)
	        {
	           var user=new Object();
	           user.Id=checkboxes[i].value;
	           user.Name=checkboxes[i].getAttribute("text");
	           user.Type=checkboxes[i].getAttribute("type");	           
	           object.Value.push(user);
	        }
	   }
	   object.Ok();
	   this.parentNode.parentNode.parentNode.parentNode.Dialog.Close();
	};
	
    var space=document.createTextNode("  ");
    toolbarLeft.appendChild(space);
	
	var cancelButton=document.createElement("input");
	cancelButton.setAttribute("type","button");
	toolbarLeft.appendChild(cancelButton);  	
	cancelButton.className="Button";
	cancelButton.value=" 取  消 ";
	cancelButton.onmouseover=function ()
	{
	    this.className="ButtonOver";
	}
	cancelButton.onmouseout=function ()
	{
	    this.className="Button";
	}
	cancelButton.onclick=function ()
	{
	   this.parentNode.parentNode.parentNode.parentNode.Dialog.Close();
	}
	
	var tree=new Tree();
	tree.AddNode(organize,"../User/images/root.gif","组织结构","组织结构","Open",true,"User_Root_Menu","100","0");
	organize.childNodes[0].Expand();
}

function Tree(container)
{  
        var object=this;
        
        this.AddNode=function (container,icon,name,text,status,isLoad,menuName,id,fid)
        {                   
			var node=document.createElement("div");     
			container.appendChild(node);
			node.className="Node";     
			node.LoadData=function (callback)
			{
				if (!isLoad) return;
				var node=this;	
    			isLoad=false;                        
				var request=new Request();
				request.Url="../Service/User.asmx/GetRoleUsersByRoleId?RoleId="+id;
				request.Callback=function (httpRequest)
				{
					if (httpRequest.status==200)
					{
					    var roles=httpRequest.responseXML.getElementsByTagName("role");		
					    var users=httpRequest.responseXML.getElementsByTagName("user");		
					    if ((roles.length>0)||(users.length>0))
					    {
							var nodeChild=document.createElement("div");  
							nodeChild.className="NodeChild";
							node.appendChild(nodeChild);  
						};			
						for (i=0;i<roles.length;i++)
						{
							 var roleId=roles[i].getAttribute("id");
						     var name=roles[i].getAttribute("name");							
							object.AddNode(nodeChild,"../User/images/folders.gif",name,text+"/"+name,"Open",true,"User_Role_Menu",roleId,id);  		       					       
						};	
						for (i=0;i<users.length;i++)
						{
							 var userName=users[i].getAttribute("userName");
						     var name=users[i].getAttribute("name");							
							 object.AddNode(nodeChild,"../User/images/user.gif",name,text+"/"+name,"Leaf",true,"User_User_Menu",userName,id);  		       					       
						};
						status="Open";
						node.Expand();
						if (callback) callback();
					};					
					delete httpRequest;
					httpRequest=null;			
				}; 
				request.Start();
				   
			}; 
			node.Expand=function ()
			{				
				switch (status)
				{
					case "Open":
						status="Close";           
						this.LoadData();
						var nodeChild=this.childNodes[1];
						if (nodeChild)
						{                        
							nodeChild.style.display="block";       
							var height=nodeChild.offsetHeight;
							nodeChild.style.overflow="hidden"; 	
							nodeChild.style.height="1px";                  
							this.Show(height);
						}
						break;
					case "Close":
						status="Open";
						var nodeChild=this.childNodes[1];
						if (nodeChild)
						{  
							var height=nodeChild.offsetHeight;
							nodeChild.style.overflow="hidden"; 	
							this.Hide(height);   
						} 
						break;
				}
				var stateImage=this.childNodes[0].childNodes[0].childNodes[0];
				stateImage.src="../user/images/"+status+".gif";
			}
			node.Show=function (height)
			{                
				var node=this;
				var nodeChild=this.childNodes[1];
				if (nodeChild.offsetHeight+parseInt(height/10)<height)            
				{
					nodeChild.style.height=nodeChild.offsetHeight+parseInt(height/10)+"px";
					window.setTimeout(function (){node.Show(height)},10)
				}
				else
				{  					
					nodeChild.style.overflow="";   
					nodeChild.style.height="";	  
										
				}
			};
			node.Hide=function (height)
			{
				var node=this;
				var nodeChild=this.childNodes[1];
				if (nodeChild.offsetHeight-parseInt(height/10)>0)            
				{
					nodeChild.style.height=nodeChild.offsetHeight-parseInt(height/10)+"px";
					window.setTimeout(function (){node.Hide(height);},10)
				}
				else
				{
				    nodeChild.className="NodeChild";
					nodeChild.style.overflow="";                   
					nodeChild.style.display="none";
					nodeChild.style.height="";
				}                
			};  				
			
			    
			var nodeName=document.createElement("div");  
			node.appendChild(nodeName); 
			nodeName.className="NodeName";
			nodeName.innerHTML="<div class='NodeNameIcon'><img src='../User/images/"+status+".gif'><input type='checkbox' value='"+id+"' text='"+text+"' type='"+(status=="Leaf"?"User":"Role")+"'><img src='"+icon+"'></div><div class='NodeNameText' onmouseover=\"javascript:this.className='NodeNameTextOver'\" onmouseout=\"javascript:this.className='NodeNameText'\">"+name+"</div>";             
			nodeName.childNodes[0].childNodes[0].onclick=function ()
			{
				this.parentNode.parentNode.parentNode.Expand();				
			};    
			
			nodeName.childNodes[0].childNodes[1].onclick=function ()
			{
				var nodeChild=this.parentNode.parentNode.parentNode.childNodes[1];
				if (!nodeChild) return;
				var checkboxes=nodeChild.getElementsByTagName("input");
				for (var i=0;i<checkboxes.length;i++)
				{
				    checkboxes[i].checked=this.checked;
				}
			};      						  
	            
			delete nodeName;
			nodeName=null;
			delete node;
			node=null;      
			delete container;
			container=null;      
    }
};

function Dict(id,name)
{
    var object=this;
    this.Value=new Object();
    
	var dialog=new Dialog("选择"+name);
	var dialogContent=dialog.Dialog.childNodes[1];
	dialog.Dialog.style.top=document.documentElement.scrollTop+50+"px";
	
	var organize=document.createElement("div");	
	organize.className="Section";
	dialogContent.appendChild(organize); 
	
	var toolbar=document.createElement("div");
	toolbar.className="DialogToolBar";
	dialogContent.appendChild(toolbar);
	
	var toolbarLeft=document.createElement("div");
	toolbarLeft.className="DialogToolItemLeft";
	toolbar.appendChild(toolbarLeft);
	
	var okButton=document.createElement("input");
	okButton.setAttribute("type","button");
	toolbarLeft.appendChild(okButton);  	
	okButton.className="Button";
	okButton.value=" 确  定 ";
	okButton.onmouseover=function ()
	{
	    this.className="ButtonOver";
	};
	okButton.onmouseout=function ()
	{
	    this.className="Button";
	};
	okButton.onclick=function ()
	{
	   var organize=this.parentNode.parentNode.parentNode.childNodes[0];
	   var checkboxes=organize.getElementsByTagName("input");
	   for (var i=0;i<checkboxes.length;i++)
	   {
	        if (checkboxes[i].checked)
	        {
	           object.Value.Id=checkboxes[i].value;
	           object.Value.Name=checkboxes[i].getAttribute("text");
	           break;    	          
	        };
	   };
	   object.Ok();
	   this.parentNode.parentNode.parentNode.parentNode.Dialog.Close();
	};
	
    var space=document.createTextNode("  ");
    toolbarLeft.appendChild(space);
	
	var cancelButton=document.createElement("input");
	cancelButton.setAttribute("type","button");
	toolbarLeft.appendChild(cancelButton);  	
	cancelButton.className="Button";
	cancelButton.value=" 取  消 ";
	cancelButton.onmouseover=function ()
	{
	    this.className="ButtonOver";
	}
	cancelButton.onmouseout=function ()
	{
	    this.className="Button";
	}
	cancelButton.onclick=function ()
	{
	   this.parentNode.parentNode.parentNode.parentNode.Dialog.Close();
	}
	
	var tree=new DictTree();
	tree.AddNode(organize,"../Dict/images/root.gif",name,name,"Open",true,"System_Expand_Menu",id,"0");
	organize.childNodes[0].Expand();
}

function DictTree(container)
{  
        var object=this;
        
        this.AddNode=function (container,icon,name,text,status,isLoad,menuName,id,fid,url)
        {                   
			var node=document.createElement("div");     
			container.appendChild(node);
			node.className="Node"; 
			node.Icon=icon;   
			node.Name=name; 		
			node.Text=text;
			node.Status=status;
			node.IsLoad=isLoad;
			node.MenuName=menuName;
			node.Id=id;
			node.Fid=fid;
			node.Url=url;	
			
			node.LoadData=function (callback)
			{
				if (!this.IsLoad) return;
				var node=this;	
				this.SetText("加载中...");
				var request=new Request();
				request.Url="../Service/Framework.asmx/GetDictsById?Id="+node.Id;
				request.Callback=function (httpRequest)
				{
					if (httpRequest.status==200)
					{
					    var dicts=httpRequest.responseXML.getElementsByTagName("dict");		
					    if (dicts.length>0)
					    {
							var nodeChild=document.createElement("div");  
							nodeChild.className="NodeChild";
							node.appendChild(nodeChild);  
						};			
						for (i=0;i<dicts.length;i++)
						{
							 var id=dicts[i].getAttribute("id");
						     var name=dicts[i].getAttribute("name");	
						     var menu=dicts[i].getAttribute("menu");
						     if (menu!="Dict_Leaf_Menu")
						     { 	 						
							        object.AddNode(nodeChild,"../Dict/images/actions.gif",node.Name+"-"+name,name,"Open",true,"Dict_Node_Menu",id,node.Id,"ShowDicts.aspx?Id="+id);  		       					       
						     }	
						     else
						     {    													
							        object.AddNode(nodeChild,"../Dict/images/action.gif",node.Name+"-"+name,name,"Leaf",false,"Dict_Leaf_Menu",id,node.Id,"ShowDict.aspx?Id="+id);  		       					       
						     };
						};
						node.Status="Open";
						node.IsLoad=false;  
						node.SetText(node.Text);  
						node.Expand();
						if (callback) callback();
					};					
					delete httpRequest;
					httpRequest=null;			
				}; 
				request.Start();
				   
			}; 
			node.Expand=function ()
			{				
				switch (this.Status)
				{
					case "Open":
						this.Status="Close";           
						this.LoadData();
						var nodeChild=this.childNodes[1];
						if (nodeChild)
						{                        
							nodeChild.style.display="block";       
							var height=nodeChild.offsetHeight;
							nodeChild.style.overflow="hidden"; 	
							nodeChild.style.height="8px";                  
							this.Show(height);
						}
						break;
					case "Close":
						this.Status="Open";
						var nodeChild=this.childNodes[1];
						if (nodeChild)
						{  
							var height=nodeChild.offsetHeight;
							nodeChild.style.overflow="hidden"; 	
							this.Hide(height);   
						} 
						break;
				}
				var stateImage=this.childNodes[0].childNodes[0].childNodes[0];
				stateImage.src="../Dict/images/"+this.Status+".gif";
			}
			node.Show=function (height)
			{                
				var node=this;
				var nodeChild=this.childNodes[1];
				if (nodeChild.offsetHeight+parseInt(height/10)<height)            
				{
					nodeChild.style.height=nodeChild.offsetHeight+parseInt(height/10)+"px";
					window.setTimeout(function (){node.Show(height)},10)
				}
				else
				{  					
					nodeChild.style.overflow="";   
					nodeChild.style.height="";										
				}
			};
			node.Hide=function (height)
			{
				var node=this;
				var nodeChild=this.childNodes[1];
				if (nodeChild.offsetHeight-parseInt(height/10)>0)            
				{
					nodeChild.style.height=nodeChild.offsetHeight-parseInt(height/10)+"px";
					window.setTimeout(function (){node.Hide(height);},10)
				}
				else
				{
				    nodeChild.className="NodeChild";
					nodeChild.style.overflow="";                   
					nodeChild.style.display="none";
					nodeChild.style.height="";
				}                
			};  

			node.SetText=function (value)
			{
			    var nodeName=this.childNodes[0].childNodes[1];
			    nodeName.innerHTML=value;
			};	
		           
			var nodeName=document.createElement("div");  
			node.appendChild(nodeName); 
			nodeName.className="NodeName";
			nodeName.innerHTML="<div class='NodeNameIcon'><img src='../Dict/images/"+status+".gif'><input type='radio' id='Dict' name='Dict' value='"+id+"' text='"+name+"'><img src='"+icon+"'></div><div class='NodeNameText' onmouseover=\"javascript:this.className='NodeNameTextOver'\" onmouseout=\"javascript:this.className='NodeNameText'\">"+text+"</div>";             
			nodeName.childNodes[0].childNodes[0].onclick=function ()
			{
				this.parentNode.parentNode.parentNode.Expand();				
			};  
			delete nodeName;
			nodeName=null;
			delete node;
			node=null;      
			delete container;
			container=null;      
    }
}
function WinBasic()
{
    try
	{	   
	    var winBasic = new ActiveXObject("WinBasic.Export");
        return winBasic;   
	}
	catch(e)
	{
		var control=document.createElement("iframe");	
		document.body.appendChild(control); 	
	    control.style.display="none";
	    control.contentWindow.document.open();
	    control.contentWindow.document.writeln("<html>");
	    control.contentWindow.document.writeln("<head>");
	    control.contentWindow.document.writeln("</head>");
	    control.contentWindow.document.writeln("<body>");
	    control.contentWindow.document.writeln('<OBJECT codeBase="WinBasic.CAB#version=1,0,0,0"	height="100px" width="100px" classid="CLSID:1426301E-80D0-4671-B802-D38B43BB2AA2" VIEWASTEXT></OBJECT>');	
	    control.contentWindow.document.writeln("</body>");
	    control.contentWindow.document.writeln("</html>");
	    control.contentWindow.document.close();	
	    return null;
	}
}
//导出
function Export()
{
    var winbasic=WinBasic();
    if (winbasic)
    {
        var excelObject=winbasic.ExportToExcel(document.getElementById("Reports"));
        excelObject.Sheets(1).Range("A1").Select();		
        excelObject.Sheets(1).UsedRange.Columns.AutoFit(); 	
    }
}

//导出
function ExportWord()
{
    var winbasic=WinBasic();
    if (winbasic)
    {
        var WordObject=winbasic.CreateWordObject();
    }
}

//打印预览
function Preview()
{
    var winbasic=WinBasic();
    if (winbasic)
    {
        winbasic.PagePreview(document.getElementById("Reports"));
    }
}
function SizeWindow()
{
    if (parent.content.cols=="23%,77%")
    {
        parent.content.cols="0%,100%";
    }
    else
    {
        parent.content.cols="23%,77%";
    }
}

function GetMenu(src,path)
{
   if (!src.PopMenu)
   {
       var popMenu=document.createElement("div");
       popMenu.className="Menu";
       document.body.childNodes[0].appendChild(popMenu);
       src.PopMenu=popMenu; 
       popMenu.onmouseover=function ()
       {
          this.style.display="block";
       }
       src.onmouseout=function ()
       {
         this.PopMenu.style.display="none";
       }
       popMenu.onmouseout=function ()
       {
          popMenu.style.display="none";
       }   
       popMenu.ShowMenu=function ShowMenu()
       {
           if (this.childNodes.length>0)
           {
               var left=GetLeft(src);
               var top=GetTop(src)+src.offsetHeight;
               this.style.left=left+"px";
               this.style.top=top+"px";
               this.style.display="block";  
           }
       } 
       var request=new Request();
	   request.Url=path+"/Service/Action.asmx/GetActions?Id="+src.getAttribute("ActionId");
	   request.Callback=function (httpRequest)
	   {
			if (httpRequest.status==200)
			{
			    var actions=httpRequest.responseXML.getElementsByTagName("action");			   
				for (i=0;i<actions.length;i++)
				{
					 var actionId=actions[i].getAttribute("id");
				     var name=actions[i].getAttribute("name");							
				     var link=actions[i].getAttribute("link");
				     var type=actions[i].getAttribute("type");
				     if (type=="Action") continue;
				     var menuItem=document.createElement("div");
                     menuItem.innerHTML=name;
                     menuItem.className="MenuItem";
                     popMenu.appendChild(menuItem);
                     menuItem.setAttribute("Link",link);
                     menuItem.onclick=function ()
                     {        
                          location.href=this.getAttribute("Link");
                     };
                     menuItem.onmouseover=function ()
                     {        
                         this.className="MenuItemOver";
                     };
                     menuItem.onmouseout=function ()
                     {
                         this.className="MenuItem";
                     };
				};
                popMenu.ShowMenu();
		    };					
			delete httpRequest;
			httpRequest=null;			
		}; 
		request.Start(); 
		return; 
   }
   src.PopMenu.ShowMenu();   
}

function LoadingDialog(title,x,y,width,height)
{
	var object=this;
	var dialogMask;

    this.Title=title?title:"无标题";
    this.Width=width?width:300;
    this.Height=height?height:200;
    this.X=x?x:(document.documentElement.clientWidth-this.Width)/2;
    this.Y=y?y:document.documentElement.scrollTop+(document.documentElement.clientHeight-this.Height)/2;

    this.SetTitle=function (title)
    {
        this.Title=title;
        headerCenter.innerHTML=this.Title;  
    }   
    this.SetXY=function (x,y)
    {
       this.X=x;
       this.Y=y;
       this.Dialog.style.left=this.X+"px";
       this.Dialog.style.top=this.Y+"px";
    }    
    
   
    this.SetRange=function (width,height)
    {
        this.Width=width;
        this.Height=height;
        this.X=x?x:(document.documentElement.clientWidth-this.Width)/2;
        this.Y=y?y:document.documentElement.scrollTop+(document.documentElement.clientHeight-this.Height)/2;
        this.Dialog.style.left=this.X+"px";
        this.Dialog.style.top=this.Y+"px";
        this.Dialog.style.width=this.Width+"px";
        this.Dialog.style.top=this.Height+"px";
    }
    
    this.Show=function ()
    {
       this.Dialog.style.display="block";
    }    
    this.Hide=function ()
    {
       if (dialogMask)
       {
          dialogMask.style.display="none";
       }
       this.Dialog.style.display="none";
    }
    
    this.Close=function ()
    {
       if (dialogMask)
       {
           dialogMask.parentNode.removeChild(dialogMask);
       }
       this.Dialog.parentNode.removeChild(this.Dialog);
       this.Dispose();
    }
    
    this.Dispose=function ()
    {       
       this.Dialog=null;
       delete dialogMask;
       dialogMask=null;
       delete object;
       object=null;
    }
    
    if (window.attachEvent) {
		window.attachEvent("onunload", this.Dispose);
	}
	else {
		window.addEventListener("unload", this.Dispose, false);
	};
    
    this.Alert=function (message)
    {
        this.showModelessDialog();
        this.Dialog.childNodes[1].innerHTML="<div class='DialogContentLeft'></div><div class='DialogContentRight'>"+message+"</div><div class='DialogContentButton'><INPUT class='Button' type='button' value='  确 定  ' onmouseover=\"javascript:this.className='ButtonOver'\" onmouseout=\"javascript:this.className='Button'\" onclick='javascript:this.parentNode.parentNode.parentNode.Dialog.Close();this.parentNode.parentNode.parentNode.Dialog.Alert.Dispose();'></div>";
        this.Dialog.lastChild.style.height=this.Dialog.offsetHeight+"px";
    }
    this.Confirm=function (message)
    {
        this.showModelessDialog();
        this.Dialog.childNodes[1].innerHTML="<br><br><br><br><br><IMG SRC='Images/loading.gif' />";	//"<div class='DialogContentLeft'></div><div class='DialogContentRight'>"+message+"</div><div class='DialogContentButton'><INPUT class='Button' type='button' value=' 确 定 ' onmouseover=\"javascript:this.className='ButtonOver'\" onmouseout=\"javascript:this.className='Button'\" onclick='javascript:this.parentNode.parentNode.parentNode.Dialog.Close();this.parentNode.parentNode.parentNode.Dialog.Confirm.OK();'>&nbsp;&nbsp;&nbsp;<INPUT class='Button' type='button' value=' 取 消 ' onmouseover=\"javascript:this.className='ButtonOver'\" onmouseout=\"javascript:this.className='Button'\" onclick='javascript:this.parentNode.parentNode.parentNode.Dialog.Close();this.parentNode.parentNode.parentNode.Dialog.Confirm.Cancel();'></div>";
        this.Dialog.lastChild.style.height=this.Dialog.offsetHeight+"px";
    }
    this.showModelessDialog=function ()
    {
        dialogMask=document.createElement("div");
        dialogMask.className="DialogMask";
        document.body.appendChild(dialogMask);	
        dialogMask.style.height=document.body.clientHeight+"px";
    }

 	var dialog=this.Dialog=document.createElement("div");
    document.body.appendChild(dialog);	

	dialog.className="Dialog";
	dialog.Dialog=this;   
    
           
    dialog.style.left=this.X+"px";
	dialog.style.top=this.Y+"px";
	dialog.style.width=this.Width+"px";	
	


	
	var header=document.createElement("div");
	header.className="DialogHeader";
	dialog.appendChild(header);
	
	var headerLeft=document.createElement("div");
	headerLeft.className="DialogHeaderLeft";
	header.appendChild(headerLeft);
	
    var expandImage=document.createElement("div");
	expandImage.className="DialogExpandImage";
	expandImage.setAttribute("State","Expand");
	expandImage.onmouseover=function () {this.className="Dialog"+this.getAttribute("State")+"ImageOver";};
	expandImage.onmouseout=function () {this.className="Dialog"+this.getAttribute("State")+"Image";};
	expandImage.onmousedown=function (e) 
	{
		if (e)
		{
			window.event=e;
		}
   		window.event.cancelBubble = true; 
   		var content=this.parentNode.parentNode.parentNode.childNodes[1];
   		var footer=this.parentNode.parentNode.parentNode.childNodes[2];
		if (this.getAttribute("State")=="Expand")
		{    	   	   
       	   	this.title="展开";
      		this.setAttribute("State","Collapse");
			content.style.display="none";
			footer.style.display="none";
		}
		else
		{
			this.title="折叠";
      		this.setAttribute("State","Expand");
			content.style.display="block";
			footer.style.display="block";
		}
		content=null;
		footer=null;
		this.className="Dialog"+this.getAttribute("State")+"ImageOver";
	} 
	headerLeft.appendChild(expandImage);
	
	
	var headerCenter=document.createElement("div");
	headerCenter.className="DialogHeaderCenter";
	headerCenter.innerHTML=this.Title;		
	header.appendChild(headerCenter);		
			
	var headerRight=document.createElement("div");
	headerRight.className="DialogHeaderRight";
	header.appendChild(headerRight);
	
	var closeImage=document.createElement("div");
	closeImage.className="DialogCloseImage";
	closeImage.title="关闭";
	closeImage.onmouseover=function () {this.className="DialogCloseImageOver";};
	closeImage.onmouseout=function () {this.className="DialogCloseImage";};
	closeImage.onmousedown=function (e) 
	{		 
	    window.event.returnValue = true;    
  		object.Close();
	}
	headerRight.appendChild(closeImage);	

		
	var content=document.createElement("div");
	content.className="DialogContent";
	dialog.appendChild(content);  
			
	var footer=document.createElement("div");
	footer.className="DialogFooter";
	dialog.appendChild(footer);  	

    var iframe=document.createElement("iframe");
	iframe.className="MaskDiv";
	dialog.appendChild(iframe);
	
	header.onmousedown=function (e)
	{		
		if (e)
		{
			window.event=e;
			window.event.srcElement=e.target;      
		}
		window.event.returnValue = true;
		var dialog=this.parentNode;   
		var header=this;
		this.style.cursor="move";
		var offsetX=window.event.clientX-GetLeft(dialog);
		var offsetY=window.event.clientY-GetTop(dialog);
		document.onmousemove=function (e)
		{
			if (e)
			{
				window.event=e;
				window.event.srcElement=e.target;      
			}
    		window.event.returnValue = true;   
    		object.SetXY(window.event.clientX-offsetX,window.event.clientY-offsetY);
         }
         document.onmouseup=function (e)
		 {
		    header.style.cursor="";
			document.onmousemove=null;
			document.onmouseup=null;
			dialog=null;
			header=null;
		 }
    }  
    delete expandImage;
	expandImage=null;
	delete closeImage;
	closeImage=null;
				
	delete headerLeft;
	headerLeft=null;
	delete headerCenter;
	headerCenter=null;				
	delete headerRight;
	headerRight=null;
	
	delete header;
	header=null;
	delete footer;
	footer=null;
	delete content;
	content=null;
	delete dialog;
	dialog=null; 
};